package neves.android.etmg.tilemap;

import neves.android.etmg.input.InputManager;
import neves.android.etmg.sprite.action.GameAction;
import android.view.KeyEvent;

public class TileInputManager implements InputManager {

	private GameAction[] keyActions = new GameAction[200];
	
	/* (non-Javadoc)
	 * @see neves.android.etmg.input.InputManager#onKeyDown(int, android.view.KeyEvent)
	 */
	public boolean onKeyDown(int keyCode, KeyEvent msg) {
		GameAction gameAct = GetKeyAction(keyCode);
		if(gameAct!=null){
			gameAct.press();
		}
		// return false allow next handler to reaction or return true;
		return true;
	}

	/* (non-Javadoc)
	 * @see neves.android.etmg.input.InputManager#onKeyUp(int, android.view.KeyEvent)
	 */
	public boolean onKeyUp(int keyCode, KeyEvent msg) {
		return true;
	}
	
	/* (non-Javadoc)
	 * @see neves.android.etmg.input.InputManager
	 */
	public void MapToKey(GameAction gameAction, int keyCode){
		keyActions[keyCode] = gameAction;
	}
	
	private GameAction GetKeyAction(int keyCode){
		if(keyCode < keyActions.length){
			return keyActions[keyCode];
		}	
		
		return null;
	}
}
